
import 'dart:async';

import 'package:flutter/services.dart';

class DeviceUtil {
  static const MethodChannel _channel =
      const MethodChannel('device_util');

  /// 获取 Android 元数据值
  static Future<dynamic> getAndroidMetaValue(String key) {
    return _channel.invokeMethod("metaValue", {"key": key});
  }

  /// 获取 iOS 信息值
  static Future<dynamic> getIosInfoValue(String key) {
    return _channel.invokeMethod("bundleInfo", {"key": key});
  }

  /// 获取 Android ID
  static Future<dynamic> getAndroidId() {
    return _channel.invokeMethod("androidId");
  }

  /// 获取 MAC 地址
  static Future<dynamic> getMacAddress() {
    return _channel.invokeMethod("macAddress");
  }

  /// 获取 IDFA (iOS 广告标识符)
  static Future<dynamic> getIdfa() {
    return _channel.invokeMethod("idfa");
  }

  /// 获取 OAID (Android 广告标识符)
  static Future<dynamic> getOaid() {
    return _channel.invokeMethod("oaid");
  }

  /// 获取唯一设备 ID
  static Future<dynamic> getUniqueDeviceId() {
    return _channel.invokeMethod("uniqueDeviceId");
  }

  /// 获取 IP 地址
  static Future<dynamic> getIpAddress() {
    return _channel.invokeMethod("ipAddress");
  }

  /// 获取应用版本名称
  static Future<dynamic> getAppVersion() {
    return _channel.invokeMethod("version");
  }

  /// 获取应用版本代码
  static Future<dynamic> getAppVersionCode() {
    return _channel.invokeMethod("versionCode");
  }

  /// 根据名称获取资源文件内容
  static Future<dynamic> getAssetsByName(String name) {
    return _channel.invokeMethod("assets", {"file": name});
  }

  /// 获取设备类型
  static Future<dynamic> getDeviceType() {
    return _channel.invokeMethod("deviceType");
  }

  /// 获取穿山甲分包渠道
  static Future<dynamic> getHumeChannel() {
    return _channel.invokeMethod("hume");
  }

  /// 获取广点通分包渠道
  static Future<dynamic> getTencentChannel() {
    return _channel.invokeMethod("tencentChannel");
  }

  /// 获取快手分包渠道
  static Future<dynamic> getKsChannel() {
    return _channel.invokeMethod("ksChannel");
  }

  /// 获取应用源目录
  static Future<dynamic> getSourceDir() {
    return _channel.invokeMethod("sourceDir");
  }

  /// 获取应用名称
  static Future<dynamic> getAppName() {
    return _channel.invokeMethod("appName");
  }

  /// 安装 APK
  static Future<dynamic> installApk(String path) {
    return _channel.invokeMethod("installApk", {"path": path});
  }

  /// 打开应用设置
  static Future<dynamic> openAppSetting() {
    return _channel.invokeMethod("openAppSetting");
  }

  /// 获取 SDK 版本
  static Future<dynamic> getSdkVersion() {
    return _channel.invokeMethod("sdkVersion");
  }

  /// 初始化 OAID SDK
  static Future<void> initOaidSdk() {
    return _channel.invokeMethod("initOaid");
  }

  /// 获取屏幕指标信息
  static Future<dynamic> getMetrics() {
    return _channel.invokeMethod('metrics');
  }

  /// 获取平台版本 (保留原有方法)
  static Future<String?> getPlatformVersion() {
    return _channel.invokeMethod<String>('getPlatformVersion');
  }
}
